﻿using MediatR;
using W.Warehouse.Api.Application.Command.AllocationCommand;
using W.Warehouse.Repository.Interface;

namespace W.Warehouse.Api.Application.CommandHandlder.AllocationCommandHadler
{
    public class AllocationDeleteRangeCommandHandler:IRequestHandler<AllocationDeleteRangeCommand,int>
    {
        private readonly IAllocationProductRepository _iallocationProductRepository;
        public AllocationDeleteRangeCommandHandler(IAllocationProductRepository allocationProductRepository)
        {
            _iallocationProductRepository = allocationProductRepository;
        }

        public async Task<int> Handle(AllocationDeleteRangeCommand request, CancellationToken cancellationToken)
        {
            var list = await _iallocationProductRepository.GetAllAsync();
            var plist = list.Where(c => request.Ids.Contains(c.AllocationProductId)).ToList();
            foreach (var item in plist)
            {
                item.IsDelete = true;
            }
            int n = await _iallocationProductRepository.UpdateRangeAsync(plist);
            return n;
        }
    }
}
